package com.nintendo.controller;

import com.nintendo.dto.CategoryDTO;
import com.nintendo.entity.Category;
import com.nintendo.response.Result;
import com.nintendo.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
@CrossOrigin
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping("/byNameAuthPage")
    public Result byNameAuthPage(@RequestBody CategoryDTO categoryDTO){
        return Result.ok().put("data",categoryService.findAllByNameAuthPage(categoryDTO));
    }
    @PostMapping("/save")
    public Result save(@RequestBody Category category){
        log.info("=====>{}",category);
        categoryService.saveCategory(category);
        return Result.ok();
    }
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        categoryService.deleteCategoryById(id);
        return Result.ok();
    }
    @GetMapping("/findCategoryAll")
    public Result getAll(){
        return Result.ok().put("data",categoryService.findAll());
    }
}
